package com.javaweb.web.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.javaweb.db.mybatis.api.DaoWapper;
import com.javaweb.db.query.QueryWapper;
import com.javaweb.exception.ServiceException;
import com.javaweb.web.service.ValidateService;

/**
 * 校验模块业务层接口实现
 * 
 * @author tank2140896
 */
@Service("validateServiceImpl")
public class ValidateServiceImpl implements ValidateService {
	
	/**
	 * 字段唯一性业务层接口实现
	 * 
	 * @param <T> 数据库映射实体类泛型
	 * @param daoWapper DaoWapper
	 * @param queryWapper 查询信息
	 * @param message 错误消息
	 */
	@Override
	public <T> void columnUniqueCheck(DaoWapper<T> daoWapper,QueryWapper<T> queryWapper,String message) {
		if(daoWapper==null||queryWapper==null||message==null) {
			throw new ServiceException("validated.permission.requestParameterError");
		}
		Long count = daoWapper.selectListCount(queryWapper);
		if(count!=null&&count.longValue()>0) {
			throw new ServiceException(message);
		}
	}

	/**
	 * 字段唯一性业务层接口实现
	 * 
	 * @param <T> 数据库映射实体类泛型
	 * @param daoWapper DaoWapper
	 * @param queryWappers 查询信息列表
	 * @param messages 错误消息列表
	 */
	@Override
	public <T> void columnUniqueCheck(DaoWapper<T> daoWapper,List<QueryWapper<T>> queryWappers,List<String> messages) {
		if(daoWapper==null||queryWappers==null||messages==null||queryWappers.size()!=messages.size()) {
			throw new ServiceException("validated.permission.requestParameterError");
		}
		for(int i=0;i<queryWappers.size();i++) {
			columnUniqueCheck(daoWapper,queryWappers.get(i),messages.get(i));
		}
	}
	
}
